package com.htfyun.eink.pw.draw.pointer;

import android.view.MotionEvent;

import androidx.annotation.NonNull;

/**
 * 特别说明:<br>
 * 1. 测试时发现, 当是电磁笔笔帽时, 会收到 2 个 MotionEvent.ACTION_HOVER_ENTER 事件.<br>
 *
 */

public enum PWPointerActionEnums {
    UNKNOWN(new int[]{MotionEvent.ACTION_MASK}, 0),
    DOWN(new int[]{MotionEvent.ACTION_DOWN, MotionEvent.ACTION_HOVER_ENTER, MotionEvent.ACTION_POINTER_DOWN}, 0x1),
    MOVE(new int[]{MotionEvent.ACTION_MOVE, MotionEvent.ACTION_HOVER_MOVE}, 0x2),
    UP(new int[]{MotionEvent.ACTION_UP, MotionEvent.ACTION_HOVER_EXIT, MotionEvent.ACTION_POINTER_UP, MotionEvent.ACTION_CANCEL}, 0x4),
    ;
    private final int[] actions;

    private final int flag;

    PWPointerActionEnums(int[] actions, int flag) {
        this.actions = actions;
        this.flag = flag;
    }

    public int getFlag() {
        return flag;
    }

    @NonNull
    public static PWPointerActionEnums actionToPWPointerActionEnums(int theAction) {
        final int action = theAction & MotionEvent.ACTION_MASK;
        PWPointerActionEnums theEnums = UNKNOWN;

        OUT:
        for (PWPointerActionEnums enums : PWPointerActionEnums.values()) {
            for (int val : enums.actions) {
                if (val == action) {
                    theEnums = enums;
                    break OUT;
                }
            }
        }

        return theEnums;
    }

}
